from PyQt4.QtGui import QWidget, QLabel, QFont, QPixmap
from ..data import game_data

class _roller(QWidget):
	def __init__(self, *args, **kw):
		QWidget.__init__(self, *args, **kw)

		font = QFont("Times", 12)
		font.setBold(True)
		self.font = font

	def digits(self, n):
		i0 = n % 10
		n -= i0
		n /= 10
		i1 = n % 10
		n -= i1
		n /= 10
		i2 = n % 10
		n -= i2
		n /= 10
		i3 = n % 10

		return [ i0, i1, i2, i3 ]


	def mk_button(self, x, s):
		l = QLabel(self)
		l.setGeometry(x, 2, 12 , 30)
		l.setFont(self.font)
		l.setText(s)
		return l

class DayRoller(_roller):
	def __init__(self, *args, **kw):
		_roller.__init__(self, *args, **kw)

		pic = QLabel(self)
		pic.setGeometry(0, 0, 136 , 30)
		path = "work/day_roller.png"
		pic.setPixmap(QPixmap(path))

		self.dd3 = self.mk_button(9, "0")
		self.dd2 = self.mk_button(22, "0")
		self.dd1 = self.mk_button(35, "0")
		self.dd0 = self.mk_button(48, "1")

	def set_day(self):
		l = self.digits(game_data.data.day)

		self.dd3.setText("{}".format(l[3]))
		self.dd2.setText("{}".format(l[2]))
		self.dd1.setText("{}".format(l[1]))
		self.dd0.setText("{}".format(l[0]))

class DateRoller(_roller):
	def __init__(self, *args, **kw):
		_roller.__init__(self, *args, **kw)

		pic = QLabel(self)
		pic.setGeometry(0, 0, 136 , 30)
		path = "work/date_roller.png"
		pic.setPixmap(QPixmap(path))

		self.dd1 = self.mk_button(9, "0")
		self.dd0 = self.mk_button(22, "0")

		self.mm1 = self.mk_button(44, "0")
		self.mm0 = self.mk_button(57, "1")

		self.yy3 = self.mk_button(81, "1")
		self.yy2 = self.mk_button(95, "2")
		self.yy1 = self.mk_button(108, "3")
		self.yy0 = self.mk_button(121, "4")

	def set_date(self):
		dd = self.digits(game_data.data.dd)
		self.dd0.setText("{}".format(dd[0]))
		self.dd1.setText("{}".format(dd[1]))

		mm = self.digits(game_data.data.mm)
		self.mm0.setText("{}".format(mm[0]))
		self.mm1.setText("{}".format(mm[1]))

		yyyy = self.digits(game_data.data.yyyy)
		self.yy0.setText("{}".format(yyyy[0]))
		self.yy1.setText("{}".format(yyyy[1]))
		self.yy2.setText("{}".format(yyyy[2]))
		self.yy3.setText("{}".format(yyyy[3]))



